//*********************************************************
//
// Output Registers used:
//   oPos - The vertex output position.
//   oT0  - original UV
//   oD0  - diffuse color
//   oD1  - specular color
//
//*********************************************************

// oPos = MVP * position
m4x4 r0, inPos, c[MODEL_VIEW_PROJECTION]
mov oPos, r0

// oT0 = texcoord
mov oT0, inUV

;// write oT1  to fight the bug...
mov oT1, inUV

mov r4.w, c[MATERIAL_SPECULAR_POWER].w

//eye-to-vertex vector
sub r7, c[MODEL_SPACE_CAMERA_POS_OOFOG_RANGE], inPos
dp3 r7.w, r7, r7
rsq r7.w, r7.w
mul r7, r7, r7.w
//common calculations end

#define SHIFT 0
#include "../common/_attenuation_point.vsh"
//r0 - normalized vertex to light vector
//r1.w  - attenuation
#undef SHIFT

dp3 r4.x, r0, inNormal		//r4.x = L * N

///calculating half-vector( vertex to light vector + eye vector )
add r3, r0, r7			//r3 = half-vector
dp3 r3.w, r3, r3
rsq r3.w, r3.w
mul r3, r3, r3.w

dp3 r4.y, r3, inNormal		//r4.y = H * N
lit r3, r4

//scale by attenuation
mul r3, r3, r1.w

mul r0, r3.y, c[VL_PLIGHT_DIFFUSE_1]
mul oD0.rgb, r0, c[MATERIAL_DIFFUSE_OPACITY]
mul oD0.a, inNormal.w, c[MATERIAL_DIFFUSE_OPACITY]

mul r0, r3.z, c[VL_PLIGHT_SPECULAR_1]
mul oD1.rgb, r0, c[MATERIAL_SPECULAR_POWER]
mov oD1.a, c[CONSTANT_0_05_1_2].x
